package com.goldgov.com.web;

import com.goldgov.kduck.web.json.JsonObject;
import com.goldgov.kduck.web.swagger.ApiField;
import com.goldgov.kduck.web.swagger.ApiParamRequest;
import com.goldgov.kduck.web.exception.JsonException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.goldgov.com.web.json.*;


/**
 * 用户模块MVC控制器类，该接口由工具生成，任何人均不能对本类中的任何代码进行调整，
 * 如需要完成本控制器类的逻辑实现，请实现同包类中的UserControllerDef接口
 * @author
 * @generateBy 0.1
 */
@RestController
@RequestMapping("/user")
@Api(tags="用户模块")
public class UserController {

    private UserControllerProxy userControllerProxy;

    @Autowired
    public UserController(UserControllerProxy userControllerProxy){
        this.userControllerProxy = userControllerProxy;
    }

    @PostMapping("/user/add")
    @ApiOperation("新增用户")
    @ApiParamRequest({
        @ApiField(name="userName",value = "用户姓名",paramType = "query"),
    })
    public JsonObject addUser(
            @RequestParam("userName") String userName 
        ){
        try {
            return new JsonObject(userControllerProxy.addUser(userName));
        } catch (JsonException e) {
            JsonObject jsonObject = new JsonObject(e.getData(),e.getCode(),e.getMessage());
            return jsonObject;
        }
    }

    @DeleteMapping("/user/delete")
    @ApiOperation("删除用户")
    @ApiParamRequest({
        @ApiField(name="ids",value = "",paramType = "query"),
    })
    public JsonObject deleteUser(
            @RequestParam("ids") String ids 
        ){
        try {
            return new JsonObject(userControllerProxy.deleteUser(ids));
        } catch (JsonException e) {
            JsonObject jsonObject = new JsonObject(e.getData(),e.getCode(),e.getMessage());
            return jsonObject;
        }
    }

    @GetMapping("/user/get")
    @ApiOperation("查看接口")
    @ApiParamRequest({
    })
    public JsonObject getUser(
        ){
        try {
            return new JsonObject(userControllerProxy.getUser());
        } catch (JsonException e) {
            JsonObject jsonObject = new JsonObject(e.getData(),e.getCode(),e.getMessage());
            return jsonObject;
        }
    }

    @PutMapping("/user/update")
    @ApiOperation("修改用户")
    @ApiParamRequest({
        @ApiField(name="userName",value = "用户姓名",paramType = "query"),
        @ApiField(name="userId",value = "用户ID",paramType = "query"),
        @ApiField(name="age",value = "用户姓名",paramType = "query"),
        @ApiField(name="birthday",value = "出生日期",paramType = "query"),
    })
    public JsonObject updateUser(
            @RequestParam("userName") String userName ,
            @RequestParam("userId") String userId ,
            @RequestParam("age") String age ,
            @RequestParam("birthday") String birthday 
        ){
        try {
            return new JsonObject(userControllerProxy.updateUser(userName,userId,age,birthday));
        } catch (JsonException e) {
            JsonObject jsonObject = new JsonObject(e.getData(),e.getCode(),e.getMessage());
            return jsonObject;
        }
    }

    @GetMapping("/user/complex")
    @ApiOperation("复杂接口")
    @ApiParamRequest({
    })
    public JsonObject complex(
        ){
        try {
            return new JsonObject(userControllerProxy.complex());
        } catch (JsonException e) {
            JsonObject jsonObject = new JsonObject(e.getData(),e.getCode(),e.getMessage());
            return jsonObject;
        }
    }

}
